package settings_api

import (
	"github.com/gin-gonic/gin"
	"gvb_server/config"
	"gvb_server/core"
	"gvb_server/global"
	"gvb_server/models/ctype"
	"gvb_server/models/res"
)

func (SettingsApi) SettingUpdate(c *gin.Context) {
	var v PathVariable
	if err := c.ShouldBindUri(&v); err != nil {
		res.FailCode(res.ArgumentError, c)
		return
	}
	value := v.Name
	switch value {
	case ctype.Email:
		var jsonData config.Email
		if err := c.ShouldBindJSON(&jsonData); err != nil {
			res.FailCode(res.ArgumentError, c)
			return
		}
		global.Config.Email = jsonData
	case ctype.QQ:
		var jsonData config.QQ
		if err := c.ShouldBindJSON(&jsonData); err != nil {
			res.FailCode(res.ArgumentError, c)
			return
		}
		global.Config.QQ = jsonData
	}
	core.SetYaml()
	res.OkWith(c)
}
